<?php
namespace Friend\Model;
use Think\Model;
class FriendReportModel extends Model {
	protected $connection = 'DB_BASE_DSN';
	protected $tableName = 'qyx_friend_report'; 
	
	public function getSpamList($data){
		$map = array();
		if(!empty($data['searchKey'])){
			$map['content']  = array('like','%'.$data['searchKey'].'%');
		}
		if(!empty($data['spamtype'])){
			$map['spamtype']  = $data['spamtype'];
		}
		
		$total = $this->where($map)->count();
		$fields = array('id','custid','tcustid','content','spamtype','createtime','updatetime');
		
		if(empty($data['sortField']))$data['sortField'] = "id";
		if(empty($data['sortOrder']))$data['sortOrder'] = "desc";
		
		if(empty($data['pageSize']) && empty($data['pageIndex']))
			$result = $this->field($fields)->where($map)->order("{$data['sortField']} {$data['sortOrder']}")->select();
		else 
			$result = $this->field($fields)->where($map)->order("{$data['sortField']} {$data['sortOrder']}")->limit($data['pageIndex']*$data['pageSize'] , $data['pageSize'])->select();
		
		
		return array('total'=>$total , 'data'=>$result);
	}
	
	
	public function addSpam($data){
		$result = $this->add($data);
		return $result;
	}
	
	public function getSpam($data){
		$map['custid'] = $data['custid'];
		$map['tcustid'] = $data['tcustid'];
		$result = $this->where($map)->find();
		return $result;
	}
	
	public function deleteSpam($data){
		$map['id'] = $data['id'];
		$result = $this->where($map)->delete();
		return $result;
	}
	
}


